﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace E1_eMart.admin
{
    public partial class dashboard : System.Web.UI.Page
    {
        protected TaiKhoan gTaiKhoan = new TaiKhoan();
        protected List<Object> list = new List<Object>();
        protected List<string> listColumn = new List<string>();
        private DataClasses1DataContext edata = new DataClasses1DataContext();
        protected List<ChiTietDauGia> listChiTietDauGia = new List<ChiTietDauGia>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null)
            {
                gTaiKhoan = (TaiKhoan)Session["username"];
            }
            if (Request.Params["id"] != null)
            {
                string strID = Request.Params["id"];
                ShowStatistics(strID);
            }
            
        }

        private void ShowStatistics(String id)
        {
            switch (id)
            {
                case "tkdt": ShowThongKeDoanhThu();
                    break;
                case "slgd": ShowSoLuongGiaoDich();
                    break;
                case "sspgd": ShowSoSanPhamGiaoDich();
                    break;
                case "mpgd": ShowMucPhiGiaoDich();
                    break;
            }
        }

        private void ShowThongKeDoanhThu() 
        { 
            //listChiTietDauGia = 
            //var query = from ctsp in edata.ChiTietDauGias
            //            orderby ctsp.TinhTrang
            //            group ctsp by ctsp.TinhTrang;
            //listChiTietDauGia
            var query = from ctsp in edata.ChiTietDauGias
                        orderby ctsp.TinhTrang
                        group ctsp by ctsp.TinhTrang into gr
                        select new
                        {
                            Name = gr.Key,
                            Count = gr.Count()
                        }; 
            //var query = edata.ChiTietDauGias;
            //listChiTietDauGia = query.ToList<ChiTietDauGia>();
            list = query.ToList<Object>();
            //for(int i=0;i<10;i++)
            //    listColumn.Add("Column"+i.ToString());
        }

        private void ShowSoLuongGiaoDich() 
        {
           //// listColumn.Add("STT");
           //// listColumn.Add("Tình trạng giao dịch");
           //// listColumn.Add("Số lượng");
           ////// DataClasses1DataContext edata = new DataClasses1DataContext();
           //// //var ctdg = from ct in edata.ChiTietDauGias
           //// //           group by 
           //// //for(int i=0;i<ctdg.Count;i++)
           //// //    if()
           // //var query = edata.ChiTietDauGias;
           // //var query = edata.ChiTietDauGias;
           // //listChiTietDauGia = query.ToList<ChiTietDauGia>();
           // //listChiTietDauGia = query.ToList<ChiTietDauGia>();

            //var query = edata.ChiTietDauGias;
            //listChiTietDauGia = query.ToList<ChiTietDauGia>();
            //listChiTietDauGia.GroupBy<listChiTietDauGia[0].TinhTrang>();
            //var query = from ctsp in edata.ChiTietDauGias
            //            orderby ctsp.TinhTrang
            //            group ctsp by ctsp.TinhTrang into gr
            //            select new
            //            {
            //                Name = gr.Key,
            //                Count = gr.Count()
            //            };
            ////var query = edata.ChiTietDauGias;
            ////listChiTietDauGia = query.ToList<ChiTietDauGia>();
            //list = query.ToList<Object>();
            //list.GroupBy
            var temp = new { name = "", type = "" };

            var query = from ctsp in edata.ChiTietDauGias
                        orderby ctsp.TinhTrang
                        group ctsp by ctsp.TinhTrang into gr
                        select new
                        {
                            Name = gr.Key,
                            Count = gr.Count()
                        };
            list = query.ToList<Object>();
        }

        private void ShowSoSanPhamGiaoDich() 
        { 
        }

        private void ShowMucPhiGiaoDich() 
        {
            var query = edata.ChiTietDauGias;
            listChiTietDauGia = query.ToList<ChiTietDauGia>();
        }

    }
}